import 'package:flutter/material.dart';
import 'package:heven/pages/creation/widget/base.dart';
import 'package:heven/pages/creation/widget/specialty.dart';
import 'package:heven/pages/creation/widget/tabs.dart';
import 'package:heven/widget/button.dart';

class CreationPage extends StatefulWidget {
  const CreationPage({super.key});

  @override
  State<CreationPage> createState() => _CreationPageState();
}

class _CreationPageState extends State<CreationPage> {
  int _currentIndex = 0;

  List<Widget> pages = [
    const BaseWidget(
      dialog: _showDialog,
    ),
    const SpecialtyWidget(
      dialog: _showDialog,
    ),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        toolbarHeight: 60,
        leadingWidth: 53,
        leading: GestureDetector(
          onTap: () {
            Navigator.pop(context);
          },
          child: Padding(
            padding: EdgeInsets.only(left: 23),
            child: Image.asset(
              'assets/images/close.png',
              width: 30,
              height: 30,
            ),
          ),
        ),
        title: TabsWidget(
          onChanged: (index) {
            setState(() {
              _currentIndex = index;
            });
          },
        ),
        actions: const [
          SizedBox(
            width: 53,
          )
        ],
      ),
      body: PageView.builder(
        physics: const NeverScrollableScrollPhysics(),
        itemBuilder: (BuildContext context, int index) {
          return pages[_currentIndex];
        },
      ),
    );
  }
}

void _showDialog(BuildContext context) {
  showDialog(
    context: context,
    barrierColor: Colors.black.withOpacity(0.5),
    builder: (context) {
      return Container(
        margin: const EdgeInsets.only(left: 25, right: 25),
        alignment: Alignment.center,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Padding(
              padding: const EdgeInsets.only(left: 15, right: 15),
              child: Row(
                children: [
                  Expanded(
                    flex: 1,
                    child: Container(),
                  ),
                  GestureDetector(
                    child: Image.asset(
                      'assets/images/vip_close.png',
                      width: 30,
                      height: 30,
                    ),
                    onTap: () {
                      Navigator.of(context).pop();
                    },
                  ),
                ],
              ),
            ),
            const SizedBox(
              height: 15,
            ),
            Stack(
              children: [
                Container(
                  margin: const EdgeInsets.only(left: 15, right: 15),
                  height: 270,
                  width: double.infinity,
                  decoration: const BoxDecoration(
                    image: DecorationImage(
                      image: AssetImage("assets/images/base_popup_bg.png"),
                      fit: BoxFit.fill,
                    ),
                  ),
                  child: Column(
                    children: [
                      Container(
                        height: 44,
                        margin: const EdgeInsets.only(left: 45),
                        alignment: Alignment.centerLeft,
                        child: Image.asset(
                          'assets/images/vip_title_3.png',
                          width: 143,
                        ),
                      ),
                      const Padding(
                        padding: EdgeInsets.only(top: 46, bottom: 15),
                        child: Text(
                          '创作更多音乐',
                          style: TextStyle(
                            fontSize: 18,
                            fontWeight: FontWeight.w600,
                            height: 1.3,
                            color: Colors.white,
                          ),
                        ),
                      ),
                      const Text(
                        '海量音乐风格，更多创作次数',
                        style: TextStyle(
                          fontSize: 15.0,
                          color: Colors.white,
                          fontWeight: FontWeight.w500,
                          height: 1.42,
                        ),
                      ),
                      const Padding(
                        padding: EdgeInsets.only(bottom: 0),
                        child: Text(
                          '快速创作音乐，成为音乐制作人',
                          style: TextStyle(
                            fontSize: 15.0,
                            color: Colors.white,
                            fontWeight: FontWeight.w500,
                            height: 1.42,
                          ),
                        ),
                      ),
                      const SizedBox(
                        height: 17,
                      ),
                      ButtonWidget(
                        width: 186,
                        height: 52,
                        borderRadius: 40,
                        child: const Text(
                          '立即开通会员',
                          style: TextStyle(
                            fontWeight: FontWeight.w600,
                            color: Color(0xFF000000),
                            fontSize: 15,
                          ),
                        ),
                        onTap: () {
                          Navigator.pop(context);
                          Navigator.pushNamed(context, '/vip');
                        },
                      ),
                    ],
                  ),
                ),
                Positioned(
                  top: 7,
                  right: 0,
                  child: Image.asset(
                    'assets/images/music_notes.png',
                    width: 76,
                    height: 76,
                  ),
                )
              ],
            ),
            const SizedBox(
              height: 45,
            )
          ],
        ),
      );
    },
  );
}
